#include "stdafx.h"
#include "Projectile.h"
#include "Collider.h"


Projectile::Projectile(const EEntityType& entity_type) : Entity(entity_type)
{
}


Projectile::~Projectile(void)
{
}


void Projectile::Init(SceneObject* scene_object, Grid* grid)
{
	m_scene_object = scene_object;
	SetSpeed(50.0f);
	SetLifeTime(0.3f);
}

void Projectile::Update(float deltatime)
{
	m_scene_object->m_bounding_sphere.m_position = Vec3(m_position.x, m_position.y, m_position.z);

	if (m_life_time > 0.0f)
	{
		m_position += m_direction * m_speed * deltatime;
		m_rotation += m_direction * m_speed * deltatime;
		m_scene_object->m_transform = DirectX::XMMatrixRotationRollPitchYaw(m_rotation.x , m_rotation.y, m_rotation.z) * DirectX::XMMatrixTranslation(m_position.x, m_position.y, m_position.z);
		m_life_time -= deltatime;
	}
	else
		RemoveMe();

	m_collider->Update(m_position);
}

void Projectile::SetDirection(Vector3 direction)
{
	m_direction = direction;
}

void Projectile::SetSpeed(float speed)
{
	m_speed = speed;
}

void Projectile::SetLifeTime(float life_time)
{
	m_life_time = life_time;
}